package com.wn.servlet.demo01;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yellow Docter
 * @date 2022 -06-28
 * @desc
 *
 *  servlet的处理请求的过程:
 *
 *  01 浏览器输入地址:  http://localhost:8080/day02/demo04
 *
 *  02 通过 /demo04  找到 对应的处理请求的servlet,Demo04Servlet
 *
 *  03 创建Demo04Servlet对象,   tomcat 统一管理servlet 进行创建,销毁,方法调用
 *
 *  04 创建Demo04Servlet
 *          Servlet demo04Servlet = Class.forName("com.wn.servlet.demo01.Demo04Servlet").newInstance();
 *
 *  05  处理请求  com.wn.service() 方法
 *          demo04Servlet.com.wn.service(req,resp);  tomcat会给 service方法传入2个参数
 *          com.wn.service() 方法会调用父类的方法
 *
 *     做了请求的分发
 *     private static final String METHOD_GET = "GET";
 *     private static final String METHOD_POST = "POST";
 *     protected void com.wn.service(HttpServletRequest req, HttpServletResponse resp)
 *         throws ServletException, IOException {
 *         拿到请求的方式
 *         String method = req.getMethod();
 *         if (method.equals(METHOD_GET)) {
 *                doGet(req, resp); // 多态  父类的引用指向子类的实现
 *         } else if (method.equals(METHOD_POST)) {
 *                doPost(req, resp);
 *         }
 *     }
 */
@WebServlet(urlPatterns = "/demo04")
public class Demo04Servlet extends HttpServlet {

    // 写出来请求
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }

}
